// ------------------------------------------------ mahees framework script ------------------------------------------------

//please note, like any other frame work, i dont expect you to know how each function works, just know that it does, and also know the inputs and expected outputs.
//For the above mentioned reason this code will diliberatly not be commented.

var rootUrl = getRootUrl('frameworkJs');
var customJsUrl = false;

function getRootUrl(mainJsId) {
	var Rurl = $(mainJsId).src.split('/');
	Rurl.pop();
	Rurl.pop();
	return Rurl.join('/')+'/';
}

function getCustomJsUrl(JsId) {
	var Rurl = $(JsId).src.split('/');
	Rurl.pop();
	return Rurl.join('/')+'/';
}


window.onDomReady = function(fn) {
	if (document.addEventListener) { document.addEventListener("DOMContentLoaded", fn, false); } //W3C
	else { document.onreadystatechange = function() { if (document.readyState == "interactive") { fn(); } } } //IE
}
function setupLogin() {
	username = document.getElementById('username');
	password = document.getElementById('password');
	addEvent(username, 'focus', focusField);
	addEvent(username, 'blur', blurField);
	addEvent(password, 'focus', focusField);
	addEvent(password, 'blur', blurField);
}
function addEvent(objObject, strEventName, fnHandler) { 
 	if (objObject.addEventListener) { objObject.addEventListener(strEventName, fnHandler, false); }
	else if (objObject.attachEvent) { objObject.attachEvent('on' + strEventName, fnHandler); }
}
//addEvent(window,'load',initialize);
//window.onDomReady(initialize);

function $(id) { return document.getElementById(id); }
function $$(tn, de) { return $$$(tn, de)[0]; }
function $$$(tn, de) { return (de ? de : document).getElementsByTagName(tn); }
function CE(tn) { return document.createElement(tn); }
function AC(p, c) { p.appendChild(c); }
function GD(n) { return n.firstChild.data; }
function set_html_opts(e,opts) { for (var key in opts) { e[key] = opts[key]; } }
function createLink(content, url, html_opts) {
	var new_element = CE('a');
	new_element.innerHTML = content;
	new_element.href = url;
	if (html_opts) { set_html_opts(new_element, html_opts); }
	return new_element;
}
function createDiv(html_opts) { var new_element = CE('div'); if (html_opts) { set_html_opts(new_element, html_opts); } return new_element; }
function createForm(act, html_opts, get) { 
	var formTag = CE('form'); 
	formTag.action = act;
	formTag.method = (get) ? 'GET' : 'POST';
	if (html_opts) { set_html_opts(formTag, html_opts); } 
	return formTag; 
}


function createInput(html_opts) { var inputTag = CE('input'); if (html_opts) { set_html_opts(inputTag, html_opts); } return inputTag; }
function createLabel(str, html_opts) { var label = CE('label'); label.innerHTML = str; if (html_opts) { set_html_opts(label, html_opts); } 	return label; }

//function include(js_file) { includeAbsolute(rootUrl + 'js/' + js_file + '.js'); }
function include(js_file) {
	if (!customJsUrl) { customJsUrl = getCustomJsUrl('customJs');	}
	includeAbsolute(customJsUrl + js_file + '.js');
}
function include_shared(js_file) { includeAbsolute(rootUrl + 'javascripts/shared/' + js_file + '.js'); }
function includeAbsolute(path) {
	var script = CE('script');
	script.src = path;
	script.language = 'JavaScript';
	script.type = 'text/javascript';
	AC($$('head'),script);
}
function imagePath(img_name) { return rootUrl+'images/'+img_name; }
function DW(texttowrite) { document.write(texttowrite);}
function getcookie(cname) {
	var cookiecp = document.cookie;
	if (cookiecp.length > 0) { 
		var res = cookiecp.match('(^|;) ?' + cname + '=([^;]*)(;|$)');
		if (res) { return (unescape(res[2])); }
	}
	return false;
}
function setcookie(cname, cvalue, timeToExp) {
	if (timeToExp) { var date = new Date(); date.setTime(date.getTime()+timeToExp); var expires = date.toGMTString(); }
	else { var expires = ''; }
	document.cookie = cname + '=' + escape(cvalue) + "; expires=" + expires + "; path=/";
}
function deletecookie(cname) { document.cookie = cname + '=; expires=Sat, 07 Mar 2009 05:57:57 GMT; path=/'; }
Object.prototype.clone = function ()
{
    function F() {}
    F.prototype = this;
    return new F();
};
function addEventHandler(oNode, evt, oFunc, bCaptures) {
	if (typeof(window.event) != "undefined")
		oNode.attachEvent("on"+evt, oFunc);
	else
		oNode.addEventListener(evt, oFunc, bCaptures);
}
function removeEventHandler(oNode, evt, oFunc, bCaptures) {
    if (typeof (window.event) != "undefined")
        oNode.detachEvent("on" + evt, oFunc);
    else
        oNode.removeEventListener(evt, oFunc, bCaptures);
}
function getEventTarget(e) {
    if (window.event) return window.event.srcElement;
    else return e.target;
}
var aryClassElements = [];
function getElementsByClassName( strClassName, obj ) {
    if ( obj.className == strClassName ) { aryClassElements[aryClassElements.length] = obj; }
    for ( var i = 0; i < obj.childNodes.length; i++ ) { getElementsByClassName( strClassName, obj.childNodes[i] ); }
}
function getElementsByClassName( sClassName, oNode ) {
	if (nodesWithclassName[0].className != sClassName) { var nodesWithclassName = []; }

	if (!oNode) { oNode = document; }
	if (oNode.className == sClassName) { nodesWithclassName.push(oNode); }

	var i, max = oNode.childNodes.length;
	for (i = 0; i < max; i++) {
		getElementsByClassName(sClassName, oNode.childNodes[i]);
		continue;
	}

}

/*
function eraseCookie(name) {
	createCookie(name,"",-1);
}

*/

/*
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ) {
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  document.cookie = cookie_string;
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}



*/